import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class lite_jdbc_connection {
    //创建数据库连接。
    public static Connection GetConnection(String username, String passwd) {
    String driver = "org.postgresql.Driver";
    String sourceURL =  "jdbc:postgresql://localhost:db_port/db_name";
    Connection conn = null;
    try {
        //创建数据库连接。
        conn = DriverManager.getConnection(sourceURL, username, passwd);
        System.out.println("Connection succeed!");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Connection failed!");
            return null;
        }
    return conn;
    }

    //执行SQL语句
    public static void CreateTable(Connection conn) {
        try {
            Statement stmt = conn.createStatement();
            //创建表数据
            int rc1 = stmt.executeUpdate("create table t_qeuivalence_case002 (id_number int, name varchar(50));");
            stmt.close();
            System.out.println("创建表成功！");
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("executeBatch_result = " + e.getMessage());
            System.out.println("create table failed！");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        //创建数据库连接。
        Connection conn = GetConnection("db_user", "user_passwd");
        //创建表。
        CreateTable(conn);
        //关闭数据库连接。
        try {
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
   }
}